local key = KEYS[1]
local fansUserId = ARGV[1]
local timestamp =ARGV[2]

local exists = redis.call('EXISTS', key)
if exists == 0 then
    redis.call('ZADD', key, timestamp, fansUserId)
    return -1
end

local size = redis.call('ZCARD', key)

-- 超过 5000 粉丝之后直接删除添加时间最久的数据
if size >= 5000 then
    redis.call('ZPOPMIN', key)
end

redis.call('ZADD', key, timestamp, fansUserId)

return 0

